import {PluginCommand} from "./PluginCommand";

class HoleAndCutCommand extends PluginCommand {
  constructor() {
    super();
    this.isPickEntity = false;
  }

  /**
   * 拾取元素或实体
   * @param cb
   */
  handlePickElement(cb) {
    super.handlePickElement(res => {
      if (this.isPickEntity) {
        res?.element?.forEach(object => {
          let entityId = object?.element?.params?.entityRefId;
          if (entityId) {
            super.getEntitiesByIds([entityId], res => {
              cb(res);
              this.toolQuery.highLightEntityOutline([entityId]);
            });
          }
        })
      } else {
        let elements = [];
        res?.element?.forEach(object => {
          elements.push(object?.element);
        })
        cb(elements);
      }
    })
  }

  setPickEntityStatus(isPickEntity) {
    this.isPickEntity = isPickEntity;
  }

  executeHoleCmd(cmd,cb) {
    if (this.toolQuery) {
      this.toolQuery.executeHoleCmd(cmd).then(res => {
        cb(res.data.modelObject);
      });
    }
  }

  // getInitCmdParams(type, cb){
  //   if (this.request) {
  //     this.request.execFunction(PluginCADToolFunctionType.GETINITCMDPARAMS, {type: type})
  //       .then(res => {
  //         cb(res.paramData);
  //       });
  //   }
  // }

  //创建草图点
  createSketchPoint(paramData) {
    if (this.toolQuery) {
      this.toolQuery.createSketchPoint(paramData);
    }
  }

  restoreParams(cb){
    if (this.toolQuery) {
      this.toolQuery.restoreParams().then(retValue => {
        cb(retValue.data.retParams);
      })
    }
  }

  //执行快速切削命令
  executeFastCutCmd(paramData){
    if (this.toolQuery){
      this.toolQuery.executeFastCutCmd(paramData);
    }
  }
}
const holeAndCutCommand = new HoleAndCutCommand();
export { holeAndCutCommand }
